# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
import time

import icecream
from itemadapter import ItemAdapter
from scrapy.http import Request
from scrapy.pipelines.images import ImagesPipeline

# class XlSpiderPipeline:
#     def process_item(self, item, spider):
#         return item

class FeiPipeline(ImagesPipeline):
    def get_media_requests(self, item, info):
        image_url = item['image']
        yield Request(image_url,meta = {'title':item['title']})

    def file_path(self, request, response=None, info=None):
        image_tag = request.url.split('.')[-1]
        name = request.meta['title']
        filename = '{}.{}'.format(name,image_tag)
        # icecream.ic(filename)
        return filename